home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / lpmud312.tar / lpmud312 / make_func.c < prev    next >
C/C++ Source or Header  |  1993-01-11  |  22KB  |  812 lines

  1. #ifndef lint
  2. static char yysccsid[] = "@(#)yaccpar    1.8 (Berkeley) 01/20/90";
  3. #endif
  4. #define YYBYACC 1
  5. #line 2 "make_func.y"
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <string.h>
  9. #include <fcntl.h>
  10. #include "lint.h"
  11. #include "config.h"
  12.  
  13. #define FUNC_SPEC     "make list_funcs"
  14. #define FUNC_TOKENS     "efun_tokens.y"
  15. #define PRE_LANG        "prelang.y"
  16. #define POST_LANG       "postlang.y"
  17. #define THE_LANG        "lang.y"
  18. #define BUFSIZ         1024
  19. #define NELEMS(arr)     (sizeof arr / sizeof arr[0])
  20.  
  21. #define MAX_FUNC      2048  /* If we need more than this we're in trouble! */
  22. int num_buff;
  23. /* For quick sort purposes : */
  24. char *key[MAX_FUNC], *buf[MAX_FUNC], has_token[MAX_FUNC];
  25.  
  26. int min_arg = -1, limit_max = 0;
  27.  
  28. /*
  29.  * arg_types is the types of all arguments. A 0 is used as a delimiter,
  30.  * marking next argument. An argument can have several types.
  31.  */
  32. int arg_types[200], last_current_type;
  33. /*
  34.  * Store the types of the current efun. They will be copied into the
  35.  * arg_types list if they were not already there (to save memory).
  36.  */
  37. int curr_arg_types[MAX_LOCAL], curr_arg_type_size;
  38.  
  39. void yyerror PROT((char *));
  40. int yylex();
  41. int yyparse();
  42. int ungetc PROT((int c, FILE *f));
  43. char *type_str PROT((int)), *etype PROT((int)), *etype1 PROT((int)),
  44.    *ctype PROT((int));
  45. #ifndef toupper
  46. int toupper PROT((int));
  47. #endif
  48.  
  49. void fatal(str)
  50.     char *str;
  51. {
  52.     fprintf(stderr, "%s", str);
  53.     exit(1);
  54. }
  55.  
  56. #line 53 "make_func.y"
  57. typedef union {
  58.     int number;
  59.     char *string;
  60. } YYSTYPE;
  61. #line 62 "y.tab.c"
  62. #define ID 257
  63. #define VOID 258
  64. #define INT 259
  65. #define STRING 260
  66. #define OBJECT 261
  67. #define MIXED 262
  68. #define UNKNOWN 263
  69. #define DEFAULT 264
  70. #define YYERRCODE 256
  71. short yylhs[] = {                                        -1,
  72.     0,    0,    7,    7,    8,    8,    9,    1,    1,    3,
  73.     3,    3,    3,    3,    3,    2,    2,    2,    6,    5,
  74.     4,    4,    4,
  75. };
  76. short yylen[] = {                                         2,
  77.     0,    2,    1,    0,    3,    0,    8,    1,    2,    1,
  78.     1,    1,    1,    1,    1,    0,    1,    3,    1,    1,
  79.     1,    3,    3,
  80. };
  81. short yydefred[] = {                                      1,
  82.     0,   10,   11,   12,   15,   13,   14,    0,    0,    2,
  83.     0,    9,    3,    0,    0,    0,   20,    0,    0,   21,
  84.    17,    0,    0,    0,    0,    0,   23,    0,   18,    0,
  85.    22,    5,    7,
  86. };
  87. short yydgoto[] = {                                       1,
  88.    17,   18,    9,   19,   20,   21,   14,   25,   10,
  89. };
  90. short yysindex[] = {                                      0,
  91.  -251,    0,    0,    0,    0,    0,    0, -244,  -28,    0,
  92.  -241,    0,    0,  -23,  -31,  -27,    0,  -38, -106,    0,
  93.     0,  -26,  -37,  -31,  -19, -251,    0, -234,    0,  -35,
  94.     0,    0,    0,
  95. };
  96. short yyrindex[] = {                                      0,
  97.     0,    0,    0,    0,    0,    0,    0,    0,  -41,    0,
  98.   -15,    0,    0,    0,  -40,    0,    0,  -14,  -39,    0,
  99.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  100.     0,    0,    0,
  101. };
  102. short yygindex[] = {                                      0,
  103.    25,    0,    0,    0,    2,    5,    0,    0,    0,
  104. };
  105. #define YYTABLESIZE 232
  106. short yytable[] = {                                       8,
  107.    16,   19,    8,   16,   19,   24,    2,    3,    4,    5,
  108.     6,    7,   11,   12,   16,   13,   15,   26,   22,   27,
  109.    28,   30,   32,   33,    4,    8,    6,   31,   29,    0,
  110.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  111.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  112.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  113.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  114.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  115.     0,    0,    8,    0,    0,    0,    0,    0,    0,    0,
  116.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  117.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  118.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  119.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  120.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  121.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  122.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  123.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  124.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  125.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  126.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  127.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  128.     0,    0,    0,    0,    0,    8,    0,    0,    0,    0,
  129.     0,    0,    8,   16,   19,   23,    2,    3,    4,    5,
  130.     6,    7,
  131. };
  132. short yycheck[] = {                                      41,
  133.    41,   41,   44,   44,   44,   44,  258,  259,  260,  261,
  134.   262,  263,  257,   42,   46,  257,   40,  124,   46,   46,
  135.    58,   41,  257,   59,   40,    1,   41,   26,   24,   -1,
  136.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  137.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  138.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  139.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  140.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  141.    -1,   -1,  124,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  142.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  143.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  144.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  145.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  146.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  147.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  148.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  149.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  150.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  151.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  152.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  153.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  154.    -1,   -1,   -1,   -1,   -1,  257,   -1,   -1,   -1,   -1,
  155.    -1,   -1,  264,  264,  264,  264,  258,  259,  260,  261,
  156.   262,  263,
  157. };
  158. #define YYFINAL 1
  159. #ifndef YYDEBUG
  160. #define YYDEBUG 0
  161. #endif
  162. #define YYMAXTOKEN 264
  163. #if YYDEBUG
  164. char *yyname[] = {
  165. "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  166. 0,0,0,0,0,0,"'('","')'","'*'",0,"','",0,"'.'",0,0,0,0,0,0,0,0,0,0,0,"':'","';'",
  167. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  168. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,0,0,0,0,0,0,0,
  169. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  170. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  171. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  172. "ID","VOID","INT","STRING","OBJECT","MIXED","UNKNOWN","DEFAULT",
  173. };
  174. char *yyrule[] = {
  175. "$accept : funcs",
  176. "funcs :",
  177. "funcs : funcs func",
  178. "optional_ID : ID",
  179. "optional_ID :",
  180. "optional_default : DEFAULT ':' ID",
  181. "optional_default :",
  182. "func : type ID optional_ID '(' arg_list optional_default ')' ';'",
  183. "type : basic",
  184. "type : basic '*'",
  185. "basic : VOID",
  186. "basic : INT",
  187. "basic : STRING",
  188. "basic : MIXED",
  189. "basic : UNKNOWN",
  190. "basic : OBJECT",
  191. "arg_list :",
  192. "arg_list : typel2",
  193. "arg_list : arg_list ',' typel2",
  194. "typel2 : typel",
  195. "arg_type : type",
  196. "typel : arg_type",
  197. "typel : typel '|' arg_type",
  198. "typel : '.' '.' '.'",
  199. };
  200. #endif
  201. #define yyclearin (yychar=(-1))
  202. #define yyerrok (yyerrflag=0)
  203. #ifdef YYSTACKSIZE
  204. #ifndef YYMAXDEPTH
  205. #define YYMAXDEPTH YYSTACKSIZE
  206. #endif
  207. #else
  208. #ifdef YYMAXDEPTH
  209. #define YYSTACKSIZE YYMAXDEPTH
  210. #else
  211. #define YYSTACKSIZE 500
  212. #define YYMAXDEPTH 500
  213. #endif
  214. #endif
  215. int yydebug;
  216. int yynerrs;
  217. int yyerrflag;
  218. int yychar;
  219. short *yyssp;
  220. YYSTYPE *yyvsp;
  221. YYSTYPE yyval;
  222. YYSTYPE yylval;
  223. short yyss[YYSTACKSIZE];
  224. YYSTYPE yyvs[YYSTACKSIZE];
  225. #define yystacksize YYSTACKSIZE
  226. #line 165 "make_func.y"
  227.  
  228. struct type {
  229.     char *name;
  230.     int num;
  231. } types[] = {
  232. { "void", VOID },
  233. { "int", INT },
  234. { "string", STRING },
  235. { "object", OBJECT },
  236. { "mixed", MIXED },
  237. { "unknown", UNKNOWN }
  238. };
  239.  
  240. FILE *f;
  241. int current_line = 1;
  242.  
  243. int main(argc, argv)
  244.     int argc;
  245.     char **argv;
  246. {
  247.     int i, fdr, fdw;
  248.     char buffer[BUFSIZ + 1];
  249.  
  250.     if ((f = popen(FUNC_SPEC, "r")) == NULL) { 
  251.     perror(FUNC_SPEC);
  252.     exit(1);
  253.     }
  254.     yyparse();
  255.     /* Now sort the main_list */
  256.     for (i = 0; i < num_buff; i++) {
  257.        int j;
  258.        for (j = 0; j < i; j++)
  259.        if (strcmp(key[i], key[j]) < 0) {
  260.           char *tmp;
  261.           int tmpi;
  262.           tmp = key[i]; key[i] = key[j]; key[j] = tmp;
  263.           tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp;
  264.           tmpi = has_token[i];
  265.           has_token[i] = has_token[j]; has_token[j] = tmpi;
  266.            }
  267.     }
  268.     /* Now display it... */
  269.     printf("{\n");
  270.     for (i = 0; i < num_buff; i++)
  271.        printf("%s", buf[i]);
  272.     printf("\n};\nint efun_arg_types[] = {\n");
  273.     for (i=0; i < last_current_type; i++) {
  274.     if (arg_types[i] == 0)
  275.         printf("0,\n");
  276.     else
  277.         printf("%s,", ctype(arg_types[i]));
  278.     }
  279.     printf("};\n");
  280.     pclose(f);
  281.     /*
  282.      * Write all the tokens out.  Do this by copying the
  283.      * pre-include portion of lang.y to lang.y, appending
  284.      * this information, then appending the post-include
  285.      * portion of lang.y.  It's done this way because I don't
  286.      * know how to get YACC to #include %token files.  *grin*
  287.      */
  288.     if ((fdr = open(PRE_LANG, O_RDONLY)) < 0) {
  289.        perror(PRE_LANG);
  290.        exit(1);
  291.     }
  292.     unlink(THE_LANG);
  293.     if ((fdw = open(THE_LANG, O_CREAT | O_WRONLY, 0444)) < 0) {
  294.        perror(THE_LANG);
  295.        exit(1);
  296.     }
  297.     while (i = read(fdr, buffer, BUFSIZ))
  298.        write(fdw, buffer, i);
  299.     close(fdr);
  300.     for (i = 0; i < num_buff; i++) {
  301.        if (has_token[i]) {
  302.           char *str;   /* It's okay to mung key[*] now */
  303.           for (str = key[i]; *str; str++)
  304.             if (islower(*str)) *str = toupper(*str);
  305.           sprintf(buffer, "%%token F_%s\n", key[i]);
  306.           write(fdw, buffer, strlen(buffer));
  307.        }
  308.     }
  309.     if ((fdr = open(POST_LANG, O_RDONLY)) < 0) {
  310.        perror(POST_LANG);
  311.        exit(1);
  312.     }
  313.     while (i = read(fdr, buffer, BUFSIZ))
  314.        write(fdw, buffer, i);
  315.     close(fdr), close(fdw);
  316.     return 0;
  317. }
  318.  
  319. void yyerror(str)
  320.     char *str;
  321. {
  322.     fprintf(stderr, "%s:%d: %s\n", FUNC_SPEC, current_line, str);
  323.     exit(1);
  324. }
  325.  
  326. int ident(c)
  327.     int c;
  328. {
  329.     char buff[100];
  330.     int len, i;
  331.  
  332.     for (len=0; isalnum(c) || c == '_'; c = getc(f)) {
  333.     buff[len++] = c;
  334.     if (len + 1 >= sizeof buff)
  335.         fatal("Local buffer in ident() too small!\n");
  336.     if (len == sizeof buff - 1) {
  337.         yyerror("Too long indentifier");
  338.         break;
  339.     }
  340.     }
  341.     (void)ungetc(c, f);
  342.     buff[len] = '\0';
  343.     for (i=0; i < NELEMS(types); i++) {
  344.     if (strcmp(buff, types[i].name) == 0) {
  345.         yylval.number = types[i].num;
  346.         return types[i].num;
  347.     }
  348.     }
  349.     if (strcmp(buff, "default") == 0)
  350.     return DEFAULT;
  351.     yylval.string = malloc(strlen(buff)+1);
  352.     strcpy(yylval.string, buff);
  353.     return ID;
  354. }
  355.  
  356. char *type_str(n)
  357.     int n;
  358. {
  359.     int i, type = n & 0xffff;
  360.  
  361.     for (i=0; i < NELEMS(types); i++) {
  362.     if (types[i].num == type) {
  363.         if (n & 0x10000) {
  364.         static char buff[100];
  365.         if (strlen(types[i].name) + 3 > sizeof buff)
  366.             fatal("Local buffer too small in type_str()!\n");
  367.         sprintf(buff, "%s *", types[i].name);
  368.         return buff;
  369.         }
  370.         return types[i].name;
  371.     }
  372.     }
  373.     return "What ?";
  374. }
  375.  
  376. int yylex1() {
  377.     register int c;
  378.     
  379.     for(;;) {
  380.     switch(c = getc(f)) {
  381.     case ' ':
  382.     case '\t':
  383.         continue;
  384.     case '#':
  385.     {
  386. #ifdef sun /* no prototype in <stdio.h> *sigh* */
  387.         extern int fscanf PROT((FILE *, char *, ...));
  388. #endif
  389.         int line;
  390.         char file[2048]; /* does any operating system support
  391.                 longer pathnames? */
  392.         if ( fscanf(f,"%d \"%s\"",&line,file ) == 2 )
  393.         current_line = line;
  394.         while(c != '\n' && c != EOF)
  395.         c = getc(f);
  396.         current_line++;
  397.         continue;
  398.     }
  399.     case '\n':
  400.         current_line++;
  401.         continue;
  402.     case EOF:
  403.         return -1;
  404.     default:
  405.         if (isalpha(c))
  406.         return ident(c);
  407.         return c;
  408.     }
  409.     }
  410. }
  411.  
  412. int yylex() {
  413.     return yylex1();
  414. }
  415.  
  416. char *etype1(n)
  417.     int n;
  418. {
  419.     if (n & 0x10000)
  420.     return "T_POINTER";
  421.     switch(n) {
  422.     case INT:
  423.     return "T_NUMBER";
  424.     case OBJECT:
  425.     return "T_OBJECT";
  426.     case STRING:
  427.     return "T_STRING";
  428.     case MIXED:
  429.     return "0";    /* 0 means any type */
  430.     default:
  431.     yyerror("Illegal type for argument");
  432.     }
  433.     return "What ?";
  434. }
  435.  
  436. char *etype(n)
  437.     int n;
  438. {
  439.     int i;
  440.     int local_size = 100;
  441.     char *buff = malloc(local_size);
  442.  
  443.     for (i=0; i < curr_arg_type_size; i++) {
  444.     if (n == 0)
  445.         break;
  446.     if (curr_arg_types[i] == 0)
  447.         n--;
  448.     }
  449.     if (i == curr_arg_type_size)
  450.     return "0";
  451.     buff[0] = '\0';
  452.     for(; curr_arg_types[i] != 0; i++) {
  453.     char *p;
  454.     if (curr_arg_types[i] == VOID)
  455.         continue;
  456.     if (buff[0] != '\0')
  457.         strcat(buff, "|");
  458.     p = etype1(curr_arg_types[i]);
  459.     /*
  460.      * The number 2 below is to include the zero-byte and the next
  461.      * '|' (which may not come).
  462.      */
  463.     if (strlen(p) + strlen(buff) + 2 > local_size) {
  464.         fprintf(stderr, "Buffer overflow!\n");
  465.         exit(1);
  466.     }
  467.     strcat(buff, etype1(curr_arg_types[i]));
  468.     }
  469.     return buff;
  470. }
  471.  
  472. char *ctype(n)
  473.     int n;
  474. {
  475.     static char buff[100];    /* 100 is such a comfortable size :-) */
  476.     char *p;
  477.  
  478.     if (n & 0x10000)
  479.     strcpy(buff, "TYPE_MOD_POINTER|");
  480.     else
  481.     buff[0] = '\0';
  482.     n &= ~0x10000;
  483.     switch(n) {
  484.     case VOID: p = "TYPE_VOID"; break;
  485.     case STRING: p = "TYPE_STRING"; break;
  486.     case INT: p = "TYPE_NUMBER"; break;
  487.     case OBJECT: p = "TYPE_OBJECT"; break;
  488.     case MIXED: p = "TYPE_ANY"; break;
  489.     case UNKNOWN: p = "TYPE_UNKNOWN"; break;
  490.     default: yyerror("Bad type!");
  491.     }
  492.     strcat(buff, p);
  493.     if (strlen(buff) + 1 > sizeof buff)
  494.     fatal("Local buffer overwritten in ctype()");
  495.     return buff;
  496. }
  497. #line 498 "y.tab.c"
  498. #define YYABORT goto yyabort
  499. #define YYACCEPT goto yyaccept
  500. #define YYERROR goto yyerrlab
  501. int
  502. yyparse()
  503. {
  504.     register int yym, yyn, yystate;
  505. #if YYDEBUG
  506.     register char *yys;
  507.     extern char *getenv();
  508.  
  509.     if (yys = getenv("YYDEBUG"))
  510.     {
  511.         yyn = *yys;
  512.         if (yyn >= '0' && yyn <= '9')
  513.             yydebug = yyn - '0';
  514.     }
  515. #endif
  516.  
  517.     yynerrs = 0;
  518.     yyerrflag = 0;
  519.     yychar = (-1);
  520.  
  521.     yyssp = yyss;
  522.     yyvsp = yyvs;
  523.     *yyssp = yystate = 0;
  524.  
  525. yyloop:
  526.     if (yyn = yydefred[yystate]) goto yyreduce;
  527.     if (yychar < 0)
  528.     {
  529.         if ((yychar = yylex()) < 0) yychar = 0;
  530. #if YYDEBUG
  531.         if (yydebug)
  532.         {
  533.             yys = 0;
  534.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  535.             if (!yys) yys = "illegal-symbol";
  536.             printf("yydebug: state %d, reading %d (%s)\n", yystate,
  537.                     yychar, yys);
  538.         }
  539. #endif
  540.     }
  541.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  542.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  543.     {
  544. #if YYDEBUG
  545.         if (yydebug)
  546.             printf("yydebug: state %d, shifting to state %d\n",
  547.                     yystate, yytable[yyn]);
  548. #endif
  549.         if (yyssp >= yyss + yystacksize - 1)
  550.         {
  551.             goto yyoverflow;
  552.         }
  553.         *++yyssp = yystate = yytable[yyn];
  554.         *++yyvsp = yylval;
  555.         yychar = (-1);
  556.         if (yyerrflag > 0)  --yyerrflag;
  557.         goto yyloop;
  558.     }
  559.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  560.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  561.     {
  562.         yyn = yytable[yyn];
  563.         goto yyreduce;
  564.     }
  565.     if (yyerrflag) goto yyinrecovery;
  566. #ifdef lint
  567.     goto yynewerror;
  568. #endif
  569. yynewerror:
  570.     yyerror("syntax error");
  571. #ifdef lint
  572.     goto yyerrlab;
  573. #endif
  574. yyerrlab:
  575.     ++yynerrs;
  576. yyinrecovery:
  577.     if (yyerrflag < 3)
  578.     {
  579.         yyerrflag = 3;
  580.         for (;;)
  581.         {
  582.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  583.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
  584.             {
  585. #if YYDEBUG
  586.                 if (yydebug)
  587.                     printf("yydebug: state %d, error recovery shifting\
  588.  to state %d\n", *yyssp, yytable[yyn]);
  589. #endif
  590.                 if (yyssp >= yyss + yystacksize - 1)
  591.                 {
  592.                     goto yyoverflow;
  593.                 }
  594.                 *++yyssp = yystate = yytable[yyn];
  595.                 *++yyvsp = yylval;
  596.                 goto yyloop;
  597.             }
  598.             else
  599.             {
  600. #if YYDEBUG
  601.                 if (yydebug)
  602.                     printf("yydebug: error recovery discarding state %d\n",
  603.                             *yyssp);
  604. #endif
  605.                 if (yyssp <= yyss) goto yyabort;
  606.                 --yyssp;
  607.                 --yyvsp;
  608.             }
  609.         }
  610.     }
  611.     else
  612.     {
  613.         if (yychar == 0) goto yyabort;
  614. #if YYDEBUG
  615.         if (yydebug)
  616.         {
  617.             yys = 0;
  618.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  619.             if (!yys) yys = "illegal-symbol";
  620.             printf("yydebug: state %d, error recovery discards token %d (%s)\n",
  621.                     yystate, yychar, yys);
  622.         }
  623. #endif
  624.         yychar = (-1);
  625.         goto yyloop;
  626.     }
  627. yyreduce:
  628. #if YYDEBUG
  629.     if (yydebug)
  630.         printf("yydebug: state %d, reducing by rule %d (%s)\n",
  631.                 yystate, yyn, yyrule[yyn]);
  632. #endif
  633.     yym = yylen[yyn];
  634.     yyval = yyvsp[1-yym];
  635.     switch (yyn)
  636.     {
  637. case 4:
  638. #line 73 "make_func.y"
  639. { yyval.string = ""; }
  640. break;
  641. case 5:
  642. #line 75 "make_func.y"
  643. { yyval.string = yyvsp[0].string; }
  644. break;
  645. case 6:
  646. #line 75 "make_func.y"
  647. { yyval.string="0"; }
  648. break;
  649. case 7:
  650. #line 78 "make_func.y"
  651. {
  652.     char buff[500];
  653.     char f_name[500];
  654.     int i;
  655.     if (min_arg == -1)
  656.         min_arg = yyvsp[-3].number;
  657.     if (yyvsp[-5].string[0] == '\0') {
  658.         int len;
  659.         if (strlen(yyvsp[-6].string) + 1 + 2 > sizeof f_name)
  660.         fatal("A local buffer was too small!(1)\n");
  661.         sprintf(f_name, "F_%s", yyvsp[-6].string);
  662.         len = strlen(f_name);
  663.         for (i=0; i < len; i++) {
  664.         if (islower(f_name[i]))
  665.             f_name[i] = toupper(f_name[i]);
  666.         }
  667.         has_token[num_buff]=1;
  668.     } else {
  669.         if (strlen(yyvsp[-5].string) + 1 > sizeof f_name)
  670.         fatal("A local buffer was too small(2)!\n");
  671.         strcpy(f_name, yyvsp[-5].string);
  672.         has_token[num_buff]=0;
  673.     }
  674.     for(i=0; i < last_current_type; i++) {
  675.         int j;
  676.         for (j = 0; j+i<last_current_type && j < curr_arg_type_size; j++)
  677.         {
  678.         if (curr_arg_types[j] != arg_types[i+j])
  679.             break;
  680.         }
  681.         if (j == curr_arg_type_size)
  682.         break;
  683.     }
  684.     if (i == last_current_type) {
  685.         int j;
  686.         for (j=0; j < curr_arg_type_size; j++) {
  687.         arg_types[last_current_type++] = curr_arg_types[j];
  688.         if (last_current_type == NELEMS(arg_types))
  689.             yyerror("Array 'arg_types' is too small");
  690.         }
  691.     }
  692.     sprintf(buff, "{\"%s\",%s,%d,%d,%s,%s,%s,%d,%s},\n",
  693.         yyvsp[-6].string, f_name, min_arg, limit_max ? -1 : yyvsp[-3].number, ctype(yyvsp[-7].number),
  694.         etype(0), etype(1), i, yyvsp[-2].string);
  695.         if (strlen(buff) > sizeof buff)
  696.              fatal("Local buffer overwritten !\n");
  697.         key[num_buff] = (char *) malloc(strlen(yyvsp[-6].string) + 1);
  698.     strcpy(key[num_buff], yyvsp[-6].string);
  699.     buf[num_buff] = (char *) malloc(strlen(buff) + 1);
  700.     strcpy(buf[num_buff], buff);
  701.         num_buff++;
  702.     min_arg = -1;
  703.     limit_max = 0;
  704.     curr_arg_type_size = 0;
  705.     }
  706. break;
  707. case 9:
  708. #line 134 "make_func.y"
  709. { yyval.number = yyvsp[-1].number | 0x10000; }
  710. break;
  711. case 16:
  712. #line 138 "make_func.y"
  713. { yyval.number = 0; }
  714. break;
  715. case 17:
  716. #line 139 "make_func.y"
  717. { yyval.number = 1; if (yyvsp[0].number) min_arg = 0; }
  718. break;
  719. case 18:
  720. #line 140 "make_func.y"
  721. { yyval.number = yyvsp[-2].number + 1; if (yyvsp[0].number) min_arg = yyval.number - 1; }
  722. break;
  723. case 19:
  724. #line 143 "make_func.y"
  725. {
  726.     yyval.number = yyvsp[0].number;
  727.     curr_arg_types[curr_arg_type_size++] = 0;
  728.     if (curr_arg_type_size == NELEMS(curr_arg_types))
  729.         yyerror("Too many arguments");
  730.     }
  731. break;
  732. case 20:
  733. #line 151 "make_func.y"
  734. {
  735.     if (yyvsp[0].number != VOID) {
  736.         curr_arg_types[curr_arg_type_size++] = yyvsp[0].number;
  737.         if (curr_arg_type_size == NELEMS(curr_arg_types))
  738.         yyerror("Too many arguments");
  739.     }
  740.     yyval.number = yyvsp[0].number;
  741.     }
  742. break;
  743. case 21:
  744. #line 160 "make_func.y"
  745. { yyval.number = (yyvsp[0].number == VOID && min_arg == -1); }
  746. break;
  747. case 22:
  748. #line 161 "make_func.y"
  749. { yyval.number = (min_arg == -1 && (yyvsp[-2].number || yyvsp[0].number == VOID));}
  750. break;
  751. case 23:
  752. #line 162 "make_func.y"
  753. { yyval.number = min_arg == -1 ; limit_max = 1; }
  754. break;
  755. #line 756 "y.tab.c"
  756.     }
  757.     yyssp -= yym;
  758.     yystate = *yyssp;
  759.     yyvsp -= yym;
  760.     yym = yylhs[yyn];
  761.     if (yystate == 0 && yym == 0)
  762.     {
  763. #if YYDEBUG
  764.         if (yydebug)
  765.             printf("yydebug: after reduction, shifting from state 0 to\
  766.  state %d\n", YYFINAL);
  767. #endif
  768.         yystate = YYFINAL;
  769.         *++yyssp = YYFINAL;
  770.         *++yyvsp = yyval;
  771.         if (yychar < 0)
  772.         {
  773.             if ((yychar = yylex()) < 0) yychar = 0;
  774. #if YYDEBUG
  775.             if (yydebug)
  776.             {
  777.                 yys = 0;
  778.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  779.                 if (!yys) yys = "illegal-symbol";
  780.                 printf("yydebug: state %d, reading %d (%s)\n",
  781.                         YYFINAL, yychar, yys);
  782.             }
  783. #endif
  784.         }
  785.         if (yychar == 0) goto yyaccept;
  786.         goto yyloop;
  787.     }
  788.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  789.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  790.         yystate = yytable[yyn];
  791.     else
  792.         yystate = yydgoto[yym];
  793. #if YYDEBUG
  794.     if (yydebug)
  795.         printf("yydebug: after reduction, shifting from state %d \
  796. to state %d\n", *yyssp, yystate);
  797. #endif
  798.     if (yyssp >= yyss + yystacksize - 1)
  799.     {
  800.         goto yyoverflow;
  801.     }
  802.     *++yyssp = yystate;
  803.     *++yyvsp = yyval;
  804.     goto yyloop;
  805. yyoverflow:
  806.     yyerror("yacc stack overflow");
  807. yyabort:
  808.     return (1);
  809. yyaccept:
  810.     return (0);
  811. }
  812.